﻿// Decompiled with JetBrains decompiler
// Type: Bannerlord.BUTR.Shared.Utils.WrappedPropertyInfo
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;

#nullable enable
namespace Bannerlord.BUTR.Shared.Utils
{
  internal sealed class WrappedPropertyInfo : PropertyInfo, INotifyPropertyChanged
  {
    private readonly object _instance;
    private readonly PropertyInfo _propertyInfoImplementation;

    public event PropertyChangedEventHandler? PropertyChanged;

    public WrappedPropertyInfo(PropertyInfo actualPropertyInfo, object instance)
    {
      this._propertyInfoImplementation = actualPropertyInfo;
      this._instance = instance;
    }

    public override PropertyAttributes Attributes => this._propertyInfoImplementation.Attributes;

    public override bool CanRead => this._propertyInfoImplementation.CanRead;

    public override bool CanWrite => this._propertyInfoImplementation.CanWrite;

    public override IEnumerable<CustomAttributeData> CustomAttributes
    {
      get => this._propertyInfoImplementation.CustomAttributes;
    }

    public override Type? DeclaringType => this._propertyInfoImplementation.DeclaringType;

    public override MethodInfo? GetMethod => this._propertyInfoImplementation.GetMethod;

    public override MemberTypes MemberType => this._propertyInfoImplementation.MemberType;

    public override int MetadataToken => this._propertyInfoImplementation.MetadataToken;

    public override Module Module => this._propertyInfoImplementation.Module;

    public override string Name => this._propertyInfoImplementation.Name;

    public override Type PropertyType => this._propertyInfoImplementation.PropertyType;

    public override Type? ReflectedType => this._propertyInfoImplementation.ReflectedType;

    public override MethodInfo? SetMethod => this._propertyInfoImplementation.SetMethod;

    public override MethodInfo[] GetAccessors(bool nonPublic)
    {
      return ((IEnumerable<MethodInfo>) this._propertyInfoImplementation.GetAccessors(nonPublic)).Select<MethodInfo, WrappedMethodInfo>((Func<MethodInfo, WrappedMethodInfo>) (m => new WrappedMethodInfo(m, this._instance))).Cast<MethodInfo>().ToArray<MethodInfo>();
    }

    public override object? GetConstantValue()
    {
      return this._propertyInfoImplementation.GetConstantValue();
    }

    public override object[] GetCustomAttributes(Type attributeType, bool inherit)
    {
      return this._propertyInfoImplementation.GetCustomAttributes(attributeType, inherit);
    }

    public override object[] GetCustomAttributes(bool inherit)
    {
      return this._propertyInfoImplementation.GetCustomAttributes(inherit);
    }

    public override IList<CustomAttributeData> GetCustomAttributesData()
    {
      return this._propertyInfoImplementation.GetCustomAttributesData();
    }

    public override MethodInfo GetGetMethod(bool nonPublic)
    {
      MethodInfo getMethod = this._propertyInfoImplementation.GetGetMethod(nonPublic);
      return (object) getMethod == null ? (MethodInfo) null : (MethodInfo) new WrappedMethodInfo(getMethod, this._instance);
    }

    public override ParameterInfo[] GetIndexParameters()
    {
      return this._propertyInfoImplementation.GetIndexParameters();
    }

    public override Type[] GetOptionalCustomModifiers()
    {
      return this._propertyInfoImplementation.GetOptionalCustomModifiers();
    }

    public override object? GetRawConstantValue()
    {
      return this._propertyInfoImplementation.GetRawConstantValue();
    }

    public override Type[] GetRequiredCustomModifiers()
    {
      return this._propertyInfoImplementation.GetRequiredCustomModifiers();
    }

    public override MethodInfo GetSetMethod(bool nonPublic)
    {
      MethodInfo setMethod = this._propertyInfoImplementation.GetSetMethod(nonPublic);
      return (object) setMethod == null ? (MethodInfo) null : (MethodInfo) new WrappedMethodInfo(setMethod, this._instance);
    }

    public override object? GetValue(object? obj, object?[]? index)
    {
      return this._propertyInfoImplementation.GetValue(this._instance, index);
    }

    public override object? GetValue(
      object? obj,
      BindingFlags invokeAttr,
      Binder? binder,
      object?[]? index,
      CultureInfo? culture)
    {
      return this._propertyInfoImplementation.GetValue(this._instance, invokeAttr, binder, index, culture);
    }

    public override bool IsDefined(Type attributeType, bool inherit)
    {
      return this._propertyInfoImplementation.IsDefined(attributeType, inherit);
    }

    public override void SetValue(object? obj, object? value, object?[]? index)
    {
      this._propertyInfoImplementation.SetValue(this._instance, value, index);
      PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
      if (propertyChanged == null)
        return;
      propertyChanged((object) this, new PropertyChangedEventArgs(this._propertyInfoImplementation.Name));
    }

    public override void SetValue(
      object? obj,
      object? value,
      BindingFlags invokeAttr,
      Binder? binder,
      object?[]? index,
      CultureInfo? culture)
    {
      this._propertyInfoImplementation.SetValue(this._instance, value, invokeAttr, binder, index, culture);
      PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
      if (propertyChanged == null)
        return;
      propertyChanged((object) this, new PropertyChangedEventArgs(this._propertyInfoImplementation.Name));
    }

    public override string? ToString() => this._propertyInfoImplementation.ToString();

    public override bool Equals(object? obj)
    {
      if (true)
        ;
      bool flag;
      if (!(obj is WrappedPropertyInfo wrappedPropertyInfo))
      {
        PropertyInfo propertyInfo = obj as PropertyInfo;
        flag = (object) propertyInfo != null ? this._propertyInfoImplementation.Equals((object) propertyInfo) : this._propertyInfoImplementation.Equals(obj);
      }
      else
        flag = this._propertyInfoImplementation.Equals((object) wrappedPropertyInfo._propertyInfoImplementation);
      if (true)
        ;
      return flag;
    }

    public override int GetHashCode() => this._propertyInfoImplementation.GetHashCode();
  }
}
